<?php
/*
 * Created on
 * Date: 2007-11-28
 * Author: William Yang
 */
require_once(dirname(__FILE__)."/../common/constants.php");
require_once(DB_SESSION_DIR_PATH."/db_interfaces.php");
require_once(PROJECT_DIR_PATH."/config.php");

class User extends ArraizableRegister{
	public $uid;
	public $name;
	public $password;
	public $rights;
	public $gender;
  	/*
  	 * public $uid; Autoincremented in database. It's not necessary to set this parameter.
  	 */
  	public $age;
	public $location;
	public $qq;
	public $hotmail;
	public $gmail;
	public $contact;
	public $hobby;
	public $position;
	public $description;
	public $province;
	public $city;
	public $regdate;
	public $session_id;
	public $goal;
	public $icon_file;
	
	public function __construct($name 		= NULL,
								$password 	= NULL,
								$rights 	= NULL,
								$gender		= NULL,
								$age		= NULL,
								$location 	= NULL,
								$qq 		= NULL,
								$hotmail 	= NULL,
								$gmail 		= NULL,
								$contact 	= NULL,
								$hobby 		= NULL,
								$position 	= NULL,
								$description= NULL,
								$province	= NULL,
								$city		= NULL,
								$regdate	= NULL,
								$uid		= NULL,
								$session_id = NULL,
								$goal		= 0,
								$icon_file	= NULL) {
			$this->uid			= $uid;
			$this->name 		= $name;
			$this->password		= $password;
			$this->rights 		= $rights;
			$this->gender		= $gender;
			$this->age			= $age;
			$this->location 	= $location;
			$this->qq 			= $qq;
			$this->hotmail 		= $hotmail;
			$this->gmail 		= $gmail;
			$this->contact 		= $contact;
			$this->hobby 		= $hobby;
			$this->position 	= $position;
			$this->description 	= $description;
			$this->province		= $province;
			$this->city			= $city;
			$this->session_id	= $session_id;
			$this->goal			= $goal;
			$this->regdate		= $regdate;
			$this->icon_file	= $icon_file;
	}
	
	public function array2copy($array, $alias = null) {
		$rawObj = parent::array2copy($array, $alias);
		
		$file = "images/no_photo.png";
		
		if ($rawObj->icon_file == null || $rawObj->icon_file == '')
			$rawObj->icon_file = $file;
			
		return $rawObj;
	}
}

class Team extends ArraizableRegister{
	const WIN  = 3;
	const DRAW = 1;
	const LOSE = 0;
	
	public $uid;
	public $captainid;
	public $name;
	public $rights;
	public $description;
	public $province;
	public $city;
	public $win;
	public $draw;
	public $lose;
	public $win_pct;
	
	public function __construct($captainid	= NULL,
								$name		= NULL,
								$rights		= NULL,
								$description= NULL,
								$province	= NULL,
								$city		= NULL,
								$win		= NULL,
								$draw		= NULL,
								$lose		= NULL,
								$win_pct	= NULL,
								$uid		= NULL) {
			$this->uid			= $uid;
			$this->name 		= $name;
			$this->rights 		= $rights;
			$this->captainid 	= $captainid;
			$this->description 	= $description;
			$this->province		= $province;
			$this->city			= $city;
			$this->win			= $win;
			$this->draw			= $draw;
			$this->lose			= $lose;
			$this->win_pct		= $win_pct;
	}
}

class Match extends ArraizableRegister{
	public $uid;
	public $name;
	public $owner;
	public $owner_name;
	public $createdate;
	public $status;
	public $property;
	
	public $playdate;
	public $rival;
	public $field;
	public $fee;
	public $hot_index;
	public $province;
	public $city;
	
	public function __construct($name		= NULL,
								$owner		= NULL,
								$owner_name	= NULL,
								$createdate	= NULL,
								$status		= NULL,
								$property	= NULL,
								$playdate	= NULL,
								$rival		= NULL,
								$field		= NULL,
								$fee		= NULL,
								$hot_index	= NULL,
								$province	= NULL,
								$city		= NULL,
								$uid		= NULL) {
			$this->uid			= $uid;
			$this->name 		= $name;
			$this->owner 		= $owner;
			$this->owner_name 	= $owner_name;
			$this->createdate 	= $createdate;
			$this->status 		= $status;
			$this->property		= $property;
			$this->playdate		= $playdate;
			$this->rival		= $rival;
			$this->field		= $field;
			$this->fee			= $fee;
			$this->hot_index	= $hot_index;
			$this->province		= $province;
			$this->city			= $city;
	}
}

class TeamMember extends ArraizableRegister{
	public $teamid;
	public $memberid;
		
	public function __construct($teamid		= NULL,
								$memberid	= NULL) {
			$this->teamid 	= $teamid;
			$this->memberid	= $memberid;
	}
}

class MatchRequest extends ArraizableRegister{
	public $teamid;
	public $matchid;
	public $status;
		
	public function __construct($teamid		= NULL,
								$matchid	= NULL,
								$status		= NULL) {
			$this->teamid 	= $teamid;
			$this->matchid	= $matchid;
			$this->status	= $status;
	}
}

class MatchDirectRequest extends ArraizableRegister{
	public $requesteeid;
	public $requesterid;
	public $matchid;
	public $status;
		
	public function __construct($requesteeid 	= NULL,
								$requesterid	= NULL,
								$matchid		= NULL,
								$status			= NULL) {
			$this->requesteeid 	= $requesteeid;
			$this->requesterid	= $requesterid;
			$this->matchid		= $matchid;
			$this->status		= $status;
	}
}

class MatchResult extends ArraizableRegister{
	public $uid;
	public $ownerscore;
	public $rivalscore;
	public $description;	
		
	public function __construct($uid		= NULL,
								$ownerscore	= NULL,
								$rivalscore	= NULL,
								$description= NULL) {
			$this->uid	 		= $uid;
			$this->ownerscore	= $ownerscore;
			$this->rivalscore	= $rivalscore;
			$this->description	= $description;
	}
}

class MemberInviteRequest extends ArraizableRegister{
	public $invited_member_uid;
	public $invite_team_uid;
	public $status;
		
	public function __construct($invited_member_uid		= NULL,
								$invite_team_uid		= NULL,
								$status					= NULL) {
			$this->invited_member_uid 	= $invited_member_uid;
			$this->invite_team_uid		= $invite_team_uid;
			$this->status				= $status;
	}
}

class MemberJoinRequest extends ArraizableRegister{
	public $member_uid;
	public $team_uid;
	public $status;
		
	public function __construct($member_uid		= NULL,
								$team_uid		= NULL,
								$status			= NULL) {
			$this->member_uid 	= $member_uid;
			$this->team_uid		= $team_uid;
			$this->status		= $status;
	}
}

class GeoCity extends ArraizableRegister{
	public $name;
	public $latitude;
	public $longitude;
		
	public function __construct($name		= NULL,
								$latitude	= NULL,
								$longitude	= NULL) {
			$this->name 		= $name;
			$this->latitude		= $latitude;
			$this->longitude	= $longitude;
	}
}

class Bulletin extends ArraizableRegister{
	public $uid;
	public $name;
	public $message;
	public $sent_at;
		
	public function __construct($name		= NULL,
								$message	= NULL,
								$sent_at	= NULL,
								$uid		= NULL) {
			$this->name 		= $name;
			$this->message		= $message;
			$this->sent_at		= $sent_at;
			$this->uid			= $uid;
	}
}

class Tournament extends ArraizableRegister{
	public $uid;
	public $name;
	public $status;
	public $host_uid;
		
	public function __construct($name		= NULL,
								$host_uid	= NULL,
								$status		= INITIATE,
								$uid		= NULL) {
			$this->name 		= $name;
			$this->host_uid		= $host_uid;
			$this->status		= $status;
			$this->uid			= $uid;
	}
}

class TournamentMatch extends ArraizableRegister{
	public $t_uid;
	public $m_uid;
			
	public function __construct($t_uid	= NULL,
								$m_uid	= NULL) {
			$this->t_uid 		= $t_uid;
			$this->m_uid		= $$m_uid;
	}
}

class Counter extends ArraizableRegister{
	public $uid;
	public $value;
			
	public function __construct($uid	= NULL,
								$value	= NULL) {
			$this->uid 		= $uid;
			$this->value	= $value;
	}
}

class Calendar extends ArraizableRegister{
	public $uid;
	public $ts_start;
	public $ts_end;
	public $alarm;
	public $summary;
	public $note;
	public $location;
			
	public function __construct($uid		= NULL,
								$ts_start	= NULL,
								$ts_end		= NULL,
								$alarm		= NULL,
								$summary	= NULL,
								$note		= NULL,
								$location	= NULL) {
			$this->uid	 	= $uid;
			$this->ts_start	= $ts_start;
			$this->ts_end	= $ts_end;
			$this->alarm	= $alarm;
			$this->summary	= $summary;
			$this->note		= $note;
			$this->location	= $location;
	}
	
	/*
	 * Convert the object to the string format for network transferring.
	 * Pattern: <start>\t<summary>\t<end>\t<note>\t<location>\t<alarm>
	 */
	public function toString() {
		$str_start = date(DateUtils::FMT_DEFAULT, $this->ts_start / 1000);
		$str_end = date(DateUtils::FMT_DEFAULT, $this->ts_end / 1000);
		
		$out = $str_start;
		$out .= "\t".$this->summary;
		$out .= "\t".$str_end;
		$out .= "\t".$this->note;
		$out .= "\t".$this->location;
		$out .= "\t".$this->alarm;
		
		return $out;
	}
}

class TournamentTeam extends ArraizableRegister{
	public $tournament_uid;
	public $team_uid;
	public $group;
	public $rank;
	public $score;
	public $status;
			
	public function __construct($tournament_uid	= NULL,
								$team_uid		= NULL,
								$group			= NULL,
								$rank			= NULL,
								$score			= NULL,
								$status			= NULL) {
			$this->tournament_uid 	= $tournament_uid;
			$this->team_uid			= $team_uid;
			$this->group			= $group;
			$this->rank				= $rank;
			$this->score			= $score;
			$this->status			= $status;
	}
}
?>
